#open up array class to add a new variation of the `join' method
class Array

=begin rdoc
    Create an alias of the join method which we are about to replace so that a
    reference to the old method can be maintained
=end
  alias :old_join :join

=begin rdoc
    Create a modified version of the `join' method which takes two parameters and
    returns a more user friendly string
=end
  def join(sep_1 = ',', sep_2 = 'and')
    mod_join(sep_1, sep_2)
  end

  protected

=begin rdoc
    This method modifies the Array on which it operates by popping the last element
    to create a user friendly version of the `join' method.
=end
  def mod_join!(sep_1, sep_2)
    if(self.length > 0)
      e = self.pop()
      "#{old_join(sep_1)} #{sep_2} #{e.to_s}"
    end
  end

=begin rdoc
  This method is the same as `mod_join!' except that it works on a duplicate copy of
  the given array and hence doesn't affect the state of the original array.
=end
  def mod_join(sep_1, sep_2)
    self.dup.mod_join!(sep_1, sep_2)
  end

end

puts ARGV.join(', ', '&')
